class Trie:

    def __init__(self):
        self.isEnd=False    #该节点是否是一个串的结束
        self.next=[None for _ in range(26)] #字母映射表
        self.alph={'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7,'i':8,'j':9,'k':10,'l':11,'m':12,'n':13,'o':14,
                   'p':15,'q':16,'r':17,'s':18,'t':19,'u':20,'v':21,'w':22,'x':23,'y':24,'z':25}
    def insert(self, word: str) -> None:
        node = self
        for ch in word:
            #当前位置的前缀元素还没有插入
            if node.next[node.alph[ch]]==None:
                node.next[node.alph[ch]]=Trie()
            node=node.next[node.alph[ch]]
        node.isEnd=True

    def search(self, word: str) -> bool:
        node=self
        for ch in word:
            node=node.next[node.alph[ch]]
            if node==None:
                return False
        return node.isEnd

    def startsWith(self, prefix: str) -> bool:
        node=self
        for ch in prefix:
            node=node.next[node.alph[ch]]
            if node==None:
                return False
        return True
# Your Trie object will be instantiated and called as such:
word='apple'
# word1='apple'
prefix='app'
obj = Trie()
obj.insert(word)
param_2 = obj.search(word)
print(param_2)
param_3 = obj.startsWith(prefix)
print(param_3)